<?php
include_once("../service/categoryService.php");
include_once("../service/dishService.php");

$catIDs = $_POST['checkbox'];
$cateId = $_GET['id'];
if (isset($catIDs)) {
    if (!empty($catIDs)) {
        foreach ($catIDs as $id) {
            $numProducts = countDishByCategory($id);
            if ($numProducts[0] <= 0) {
                removeCategory($id);
				Header("Location: ../admin-page/category.php?message_code=deleted");
				return;
            } else {
                Header("Location: ../admin-page/category.php?message_code=hasChild");
            }
        }
    }
} else if(isset($cateId)){
	$cateId = $_GET['id'];
	$numProducts = countDishByCategory($cateId);
	if($numProducts[0] <= 0){
		removeCategory($cateId);
		Header("Location: ../admin-page/category.php?message_code=deleted");
		return;
	} else {
		Header("Location: ../admin-page/category.php?message_code=hasChild");
		return;
	}
}

?>